import 'package:find_friend/const/const.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

// 圆形点击选择控件
class SelectIconWidget extends StatelessWidget {
  final double width;
  final bool isselect;
  final Function onTap;
  final EdgeInsetsGeometry margin;

  const SelectIconWidget({
    Key key, 
    this.width = 21, 
    this.isselect = false,
    this.onTap,
    this.margin
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: this.onTap,
      child: Container(
              width: width,
              height: width,
              margin: margin,
              child: Stack(
                children: [
                  Container(
                    decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      border: Border.all(color: isselect ? APP_font_black: const Color(0xffdddddd), width: 0.5)
                    ),
                  ),
                  Center(
                    child: Container(
                      width: width - 4,
                      height: width - 4,
                      decoration: BoxDecoration(
                        color: isselect ? APP_main_color : Colors.transparent,
                        shape: BoxShape.circle,
                      ),
                    ),
                  )
                ],
              ),
            ),
    );
  }
}

///
///圆叫头像
/// 
class CustomCircleAvatar extends StatelessWidget {
  final String url;
  final double size;

  const CustomCircleAvatar({Key key, this.url, this.size}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return PhysicalModel(
          color: Colors.white,
          shape: BoxShape.circle,
          clipBehavior: Clip.antiAlias,
          child: Image.network(url ?? "https://zhaota.oss-cn-shenzhen.aliyuncs.com/sys/avatar0.png", width: size, height: size, fit: BoxFit.cover,),
        );
  }
}

///
///刷新控件
///
class CustomRefreshWidget extends StatelessWidget {

  final RefreshController controller;
  final Function onRefresh;
  final Function onLoading;
  final Widget child;
  final int page;
  final bool enablePulldown;
  static int limitpage = 2;

  const CustomRefreshWidget({Key key, this.controller, this.enablePulldown = true, this.onRefresh, this.onLoading, this.child, this.page = 0}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SmartRefresher(
        controller: controller,
        enablePullDown: this.enablePulldown,
        enablePullUp: true,
        onRefresh: onRefresh,
        onLoading: onLoading,
        header: MaterialClassicHeader(),
        footer: CustomFooter(
          height: page > limitpage ? 200 : 50,
          builder: (BuildContext context,LoadStatus mode){
            Widget body ;
            if(mode==LoadStatus.idle){
              body =  Text("上拉加载");
            }
            else if(mode==LoadStatus.loading){
              body =  CupertinoActivityIndicator();
            }
            else if(mode == LoadStatus.canLoading){
                body = Text("松手加载更多");
            }
            else{
              body = Column(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  SizedBox(height: 10,),
                  Image.asset("assets/que4.png"),
                  SizedBox(height: 5,),
                  Text("到底了啊喂还刷!", style: TextStyle(fontFamily: "cute", fontSize: 15, color: Colors.black),),
                ],
              );
            }
            return Container(
              height: page > limitpage ? 200 : 50,
              child: Center(child:page > 2 ? body : Container()),
            );
          },
        ),
        child: child,
    );
  }
}


class NoNetWorkPlacholder extends StatelessWidget {

  final Function onTap;

  const NoNetWorkPlacholder({Key key, this.onTap}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Image.asset("assets/que3.png"),
          SizedBox(height: 5,),
          Text("啊咧!居然没有网络...", style: TextStyle(fontFamily: "cute", fontSize: 15, color: Colors.black),),
          SizedBox(height: 10,),
          InkWell(
            onTap: onTap,
            child: Text("重新加载", style: instanceTextStyle(14, APP_main_color, decoration: TextDecoration.underline,))
          )
        ],
      ),
    );
  }
}

class PreviewNoDataPlaceholder extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Image.asset("assets/qque1.png"),
          SizedBox(height: 5,),
          Text("TA居然什么都没有发!", style: TextStyle(fontFamily: "cute", fontSize: 15, color: Colors.black),)
        ],
      ),
    );
  }
}